home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / date / examples / exwait0.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-08  |  3.6 KB  |  151 lines

  1. unit Exwait0;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, AdTerm, AdPort, wincrt;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     ApdComPort1: TApdComPort;
  12.     ApdTerminal1: TApdTerminal;
  13.     Login: TButton;
  14.     Quit: TButton;
  15.     ApdEmulator1: TApdEmulator;
  16.     procedure LoginClick(Sender: TObject);
  17.     procedure QuitClick(Sender: TObject);
  18.     procedure ApdComPort1WaitChar(CP: TObject; C: Char);
  19.     procedure FormCreate(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.     Index : Byte;
  23.     procedure UpdateTerm(const S : String);
  24.   public
  25.     { Public declarations }
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.DFM}
  34.  
  35. procedure TForm1.UpdateTerm(const S : String);
  36. begin
  37.   ApdTerminal1.StuffString(^M^J+S+^M^J);
  38.   ApdTerminal1.ForcePaint;
  39. end;
  40.  
  41. procedure TForm1.LoginClick(Sender: TObject);
  42. var
  43.   WaitResult : Integer;
  44. begin
  45.   {Dial}
  46.   UpdateTerm('dialing...');
  47.   ApdComPort1.Output := 'ATDT260-9726'^M;
  48.  
  49.   {Wait for name prompt or dial error}
  50.   WaitResult := ApdComPort1.WaitForMultiString(
  51.                 'NO CARRIER^NO DIALTONE^BUSY^name?',
  52.                 1092, True, False, '^');
  53.  
  54.   case WaitResult of
  55.     0, 1, 2, 3 :
  56.       begin
  57.         if WaitResult = 0 then
  58.           UpdateTerm('Timed out during dial attempt')
  59.         else
  60.           UpdateTerm('Failed to connect');
  61.         ApdTerminal1.SetFocus;
  62.         Exit;
  63.       end;
  64.  
  65.     4 :
  66.       begin
  67.         UpdateTerm('Connected, entering name...');
  68.         ApdComPort1.Output := 'joe blow'^M;
  69.       end;
  70.   end;
  71.  
  72.   {Wait for password}
  73.   if not ApdComPort1.WaitForString('Password?',
  74.                                    182, True, False) then begin
  75.     UpdateTerm('Timed out waiting for password prompt');
  76.     ApdTerminal1.SetFocus;
  77.     Exit;
  78.   end;
  79.   ApdComPort1.Output := '123'^M;
  80.  
  81.   {Wait for menu Nonstop?}
  82.   if not ApdComPort1.WaitForString('Stop?', 182, True, False) then begin
  83.     UpdateTerm('Timed out waiting for prompt');
  84.     ApdTerminal1.SetFocus;
  85.     Exit;
  86.   end;
  87.   ApdComPort1.Output := ^M;
  88.  
  89.   {Wait for bulletin question}
  90.   if not ApdComPort1.WaitForString('bulletin menu', 182, True, False) then begin
  91.     UpdateTerm('Timed out waiting for prompt');
  92.     ApdTerminal1.SetFocus;
  93.     Exit;
  94.   end;
  95.   ApdComPort1.Output := 'N';
  96.  
  97.   {Wait for mail question}
  98.   if not ApdComPort1.WaitForString('continue?', 182, True, False) then begin
  99.     UpdateTerm('Timed out waiting for prompt');
  100.     ApdTerminal1.SetFocus;
  101.     Exit;
  102.   end;
  103.   ApdComPort1.Output := ^M;
  104.  
  105.   {Wait for main menu}
  106.   if not ApdComPort1.WaitForString('Command >>', 182, True, False) then begin
  107.     UpdateTerm('Timed out waiting for prompt');
  108.     ApdTerminal1.SetFocus;
  109.     Exit;
  110.   end;
  111.   ApdComPort1.Output := 'G';
  112.  
  113.   {Wait for "are you sure" question}
  114.   if not ApdComPort1.WaitForString('Are you sure',
  115.                                     182, True, False) then begin
  116.     UpdateTerm('Timed out waiting for are you sure');
  117.     ApdTerminal1.SetFocus;
  118.     Exit;
  119.   end;
  120.   ApdComPort1.Output := 'Y';
  121.  
  122.   {Wait for "NO CARRIER"}
  123.   if not ApdComPort1.WaitForString('NO CARRIER',
  124.                                    182, True, False) then begin
  125.     UpdateTerm('Timed out waiting for no connect');
  126.     ApdTerminal1.SetFocus;
  127.     Exit;
  128.   end;
  129.  
  130.   {Say we're finished}
  131.   UpdateTerm('Finished successfully!');
  132. end;
  133.  
  134. procedure TForm1.QuitClick(Sender: TObject);
  135. begin
  136.   Close;
  137. end;
  138.  
  139. procedure TForm1.ApdComPort1WaitChar(CP: TObject; C: Char);
  140. begin
  141.   ApdTerminal1.StuffChar(C);
  142.   ApdTerminal1.ForcePaint;
  143. end;
  144.  
  145. procedure TForm1.FormCreate(Sender: TObject);
  146. begin
  147.   Index := 0;
  148. end;
  149.  
  150. end.
  151.